package com.assets.Adapter;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.assets.R;
import com.assets.bean.Input_item;
import com.assets.bean.Input_item1;
import com.assets.newNHF.util.LogUtils;
import com.bumptech.glide.Glide;

import org.w3c.dom.Text;

import java.util.List;

/**
 * Created by Administrator on 2019/5/5.
 */

public class Input_Adapter_item1 extends ArrayAdapter {
    private Dialog dialog;
    private List<Input_item1> dataLsit;
    public Input_Adapter_item1(Context context, int resource, List<Input_item1> objects) {
        super(context, resource, objects);
        dataLsit=objects;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final Input_item1 linkeMain = dataLsit.get(position);
        final View view = LayoutInflater.from(getContext()).inflate(R.layout.input_adapter_item, parent,false);

        TextView rfid = (TextView) view.findViewById(R.id.rfid_tv);
        ImageView Asset_img = (ImageView) view.findViewById(R.id.Asset_img);
        TextView Asset_name = (TextView) view.findViewById(R.id.Asset_name);
        TextView Section = (TextView) view.findViewById(R.id.Section);
        TextView Code_number = (TextView) view.findViewById(R.id.Code_number);
//        TextView Custodian = (TextView) view.findViewById(R.id.Custodian);
        TextView Model = (TextView) view.findViewById(R.id.Model);
        TextView Category = (TextView) view.findViewById(R.id.Category);
        String image = linkeMain.getAsset_img();
        if (!TextUtils.isEmpty(image)) {
            Glide.with(getContext()).load(image).into(Asset_img);
        }

        Asset_name.setText(linkeMain.getAsset_name());
        Section.setText(linkeMain.getSection());
        Code_number.setText(linkeMain.getCode_number());
//        Custodian.setText(linkeMain.getCustodian());
        Model.setText(linkeMain.getModel());
        rfid.setText(linkeMain.getRfid());
//        Category.setText(linkeMain.getCategory());
//        Asset_img.setOnClickListener(v -> {
//            if (TextUtils.isEmpty(image)) {
//                LogUtils.d(image);
//                return;
//            }
//            //展示在dialog上面的大图
//            dialog = new Dialog(getContext(), R.style.FullActivity);
//            WindowManager.LayoutParams attributes = dialog.getWindow().getAttributes();
//            attributes.width = WindowManager.LayoutParams.MATCH_PARENT;
//            attributes.height = WindowManager.LayoutParams.MATCH_PARENT;
//            dialog.getWindow().setAttributes(attributes);
//            ImageView imageView = new ImageView(getContext());
//            imageView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
//            dialog.setContentView(imageView);
//            Glide.with(getContext()).load(image).into(imageView);
//            //大图的点击事件（点击让他消失）
//            dialog.show();
//            imageView.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    dialog.dismiss();
//                }
//            });
//        });
        return view;
    }


}
